package cl.loso.melon.server.action;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import cl.loso.melon.server.model.ItemLVS;
import cl.loso.melon.server.negocio.ItemSVLBO;
import com.opensymphony.xwork2.ActionSupport;

public class ItemSVLAction extends ActionSupport {
	private static Log log = LogFactory.getLog(ItemSVLAction.class);
	private static final long serialVersionUID = 1783114341654699134L;
	private List<ItemLVS> itemList;
	private String item;
	private String nombre;
	private String id;
	private ItemLVS itemLVS;
	private boolean existeItem;

	public String getItem() {
		return item;
	}

	public void setItem(String item) {
		this.item = item;
	}

	public String guardarItem() {
		try {
			if (ItemSVLBO.buscarNombre(item)) {
				ItemSVLBO.guardarItemSVL(item, nombre);
				existeItem = false;
			} else {
				existeItem = true;
			}
		} catch (Exception e) {
			log.error(e);
		}

		return ActionSupport.SUCCESS;
	}

	public String actualizarItem() {
		try {

			ItemSVLBO.actualizarItemSVL(id, item, nombre);

		} catch (Exception e) {
			log.error(e);
		}

		return ActionSupport.SUCCESS;
	}

	public String obtenerItem() {
		try {
			itemList = ItemSVLBO.obtenerItemSVL();
		} catch (Exception e) {
			log.error(e);
		}
		return ActionSupport.SUCCESS;
	}

	public String obtenerTemaPorNombre() {
		try {
			itemList = ItemSVLBO.obtenerTemaPorNombreLVS(item);
		} catch (Exception e) {
			log.error(e);
		}
		return ActionSupport.SUCCESS;
	}

	public String borrarItem() {
		try {
			ItemSVLBO.borrarItemSVL(id);
		} catch (Exception e) {
			log.error(e);
		}
		return ActionSupport.SUCCESS;
	}

	public String editarItem() {
		try {
			itemLVS = ItemSVLBO.editarItemSVL(id);
		} catch (Exception e) {
			log.error(e);
		}
		return ActionSupport.SUCCESS;
	}

	public List<ItemLVS> getItemList() {
		return itemList;
	}

	public void setItemList(List<ItemLVS> itemList) {
		this.itemList = itemList;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public ItemLVS getItemLVS() {
		return itemLVS;
	}

	public void setItemLVS(ItemLVS itemLVS) {
		this.itemLVS = itemLVS;
	}

	public String getNombre() {
		return nombre;
	}

	public void setNombre(String nombre) {
		this.nombre = nombre;
	}

	public boolean isExisteItem() {
		return existeItem;
	}

	public void setExisteItem(boolean existeItem) {
		this.existeItem = existeItem;
	}

}
